﻿#ifndef QUICREATOR_H
#define QUICREATOR_H

#include <QMainWindow>
#include<QMessageBox>
#include<QTimer>
#include<QMap>
#include<QThread>
#include<memory>
#include<opencv2/opencv.hpp>
#include"comsumepro.h"
#include"sensepro.h"
#include"producepro.h"
#include"produceprobuff.h"
#include"main/Inc/reflection.h"
#include"sentry/Inc/sentry.h"
#include"charts/Inc/paintmap.h"
#include"infantry/Inc/infantry.h"
#include"threadpool/Inc/threadpool.h"
#include <qtpropertybrowser.h>
#include <qtpropertymanager.h>
#include <qtvariantproperty.h>
#include<QSqlDatabase>
#include<QSqlError>
#include<QSqlTableModel>
#include<QSqlQuery>
#include<QHostAddress>
#include<QHostInfo>
#include<QNetworkInterface>
#include<QList>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
using namespace cv;
namespace Ui
{
class QUICreator;
}
struct dbNode
{
    QString ip;
    QString car;
    QString loginTime;
    QString logoutTime;
};

class QUICreator : public QMainWindow
{
    Q_OBJECT

public:
    explicit QUICreator(QWidget *parent = 0);
    ~QUICreator();

private:
    Ui::QUICreator *ui;
    shared_ptr<Phoenix> m_Phoenix;
    QString selectVehicle();
    QtVariantPropertyManager *m_pVarManagerCamera;
    QtVariantPropertyManager *m_pVarManagerArmor;
    QtVariantPropertyManager *m_pVarManagerBuff;
    QtVariantEditorFactory *m_pVarFactory;
    QMap<QtVariantProperty*,QString> m_property_dic;
    QString m_pOpenFilePath;
    comsumePro comThread;
    producePro proThread;
    sensePro senthread;
    produceProBuff proBuffThread;
    QMutex m_mutex;

    //图片显示
    QThread * m_threadUp;
    QThread * m_threadBottom;
    QMyRunnable *runBottom;
    QMyRunnable *runUp;
    QPixmap Up;
    QPixmap Bottom;
    //折线绘制
    QThread * m_thread;
    paintMap m_painMap;
    //数据库
    QSqlTableModel *m_dbModel;
    dbNode *node;
    bool Mat2Qimage(cv::Mat &mat,QImage &qimage);
    void initDevice();
    QImage cvMat_to_QImage(const cv::Mat &mat );
    //ui初始化
    void initXmlFile();
    void initForm();
    void initStyle();
    void initCameraParams();  // 摄像机参数初始化
    void initArmorParams();  //装甲版参数初始化
    void initBuffParams();   //神符参数初始化
    void initTranslator();
    void initTableViewDB();
    //数据库初始化
    void initDataBase();
    //ip获取
    QString GetLocalIPAddress();

protected:
    bool eventFilter(QObject *watched, QEvent *event);
    void paintEvent(QPaintEvent *); 
    void closeEvent(QCloseEvent *event);
private slots:
    void showUp(QPixmap pixMap);
    void showBottom(QPixmap pixMap);
    void paintBottom();

    void on_OpenFile_clicked();
    void on_SaveFile_clicked();
    void on_SaveAsFile_clicked();
    void on_NewFile_clicked();
    void cameraValueChanged(QtProperty *property, const QVariant &value);
    void armorValueChanged(QtProperty *property, const QVariant &value);
    void buffValueChanged(QtProperty *property, const QVariant &value);
    void on_btnRED_clicked();
    void on_btnBLUE_clicked();
    void on_ButtonDBDelete_clicked();
};

#endif // QUICREATOR_H
